package com.yueke.gemini.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


/**
 * Created by admin on 2017/4/18.
 */
public class TimeUtils {

    public static void main(String[] args) throws ParseException {
        Calendar now = Calendar.getInstance();
        System.out.println("年: " + now.get(Calendar.YEAR));
        System.out.println("月: " + (now.get(Calendar.MONTH) + 1) + "");
        System.out.println("日: " + now.get(Calendar.DAY_OF_MONTH));
        System.out.println("时: " + now.get(Calendar.HOUR_OF_DAY));
        System.out.println("分: " + now.get(Calendar.MINUTE));
        System.out.println("秒: " + now.get(Calendar.SECOND));
        System.out.println("当前时间毫秒数：" + now.getTimeInMillis());
        System.out.println(now.getTime());
    }


    public void Demo1(){
        //当前时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");//精确到毫秒
        Date current = new Date();
        String timestamp = sdf.format(current);

        Calendar now = Calendar.getInstance();
        String year = StringUtil.valueOf(now.get(Calendar.YEAR)); //年
        String month = StringUtil.valueOf(now.get(Calendar.MONTH) + 1); //月
        String day =  StringUtil.valueOf( now.get(Calendar.DAY_OF_MONTH)); //日
        now.setTime(new Date());//实例化一个日期
        String week = StringUtil.valueOf(now.get(Calendar.WEEK_OF_YEAR));//获取是第几周

        System.out.println("年:"+year);
        System.out.println("月:"+(month.length()<2?"0"+month:month));
        System.out.println("日:"+day);
        System.out.println("周:"+week);
        System.out.println("当前时间戳:"+timestamp);
    }
}
